import Cookie from 'js-cookie';

export const getCookiesInServer = (): any => {
	let service_cookie = {};
	const cookies = useRequestHeader('cookie') ?? '';
	cookies.split(';').forEach(function (val) {
		let parts = val.split('=');
		service_cookie[parts[0].trim()] = (parts[1] || '').trim();
	});
	return service_cookie;
};

export const getCookiesInClient: any = () => Cookie;

export const cookieStorage = {
	setItem(name: string, value: string) {
		Cookie.set(name, value, { expires: 1 });
	},
	getItem(name: string) {
		return Cookie.get(name);
	},
};
